package com.quwan.manager.controller;

import com.quwan.common.BaseController;
import com.quwan.common.result.ApiResult;
import com.quwan.common.result.PageResult;
import com.quwan.entity.TMemberAsk;
import com.quwan.manager.service.MemberAskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author laozhang
 * @date 2021/11/18 9:47
 */
@Api(tags = "后台意见反馈管理接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("mgr/memberAsk")
public class MemberAskController extends BaseController {

    private final MemberAskService memberAskService;

    @ApiOperation("意见反馈列表分页")
    @PostMapping("askListPage")
    public ApiResult<PageResult<TMemberAsk>> askListPage(@RequestParam(defaultValue = "1") int page,
                                                         @RequestParam(defaultValue = "10") int size,
                                                         @ApiParam("会员昵称") @RequestParam(required = false) String name,
                                                         @ApiParam("会员Id") @RequestParam(required = false) String mId,
                                                         @ApiParam("状态0未处理 1已解决 2不处理") @RequestParam(required = false) Integer status,
                                                         @ApiParam("开始时间 格式：yyyy-MM-dd") @RequestParam(required = false) String beginTime,
                                                         @ApiParam("结束时间 格式：yyyy-MM-dd") @RequestParam(required = false) String endTime) {
        PageResult<TMemberAsk> res = memberAskService.getMemberAskListPage(page,size,status,name,beginTime,endTime,mId);
        return ApiResult.success(res);
    }

    @ApiOperation("意见反馈列表")
    @PostMapping("askList")
    public ApiResult<List<TMemberAsk>> askList(@ApiParam("会员昵称") @RequestParam(required = false) String name,
                                               @ApiParam("状态0未处理 1已解决 2不处理") @RequestParam(required = false) Integer status,
                                               @ApiParam("开始时间 格式：yyyy-MM-dd") @RequestParam(required = false) String beginTime,
                                               @ApiParam("结束时间 格式：yyyy-MM-dd") @RequestParam(required = false) String endTime) {
        List<TMemberAsk> res = memberAskService.getMemberAskList(status,name,beginTime,endTime);
        return ApiResult.success(res);
    }

    @ApiOperation("意见反馈——处理")
    @PostMapping("askUpdate")
    public ApiResult<String> askUpdate(@ApiParam("主键id") @RequestParam(required = true) Long id,
                                       @ApiParam("状态0:未处理 1:已解决 2:不处理") @RequestParam(required = true) Integer status) {
        TMemberAsk memberAsk = new TMemberAsk();
        memberAsk.setId(id);
        memberAsk.setStatus(status);
        boolean b = memberAskService.updateMemberAskStatus(memberAsk);
        if(b)
           return ApiResult.success();
        else
            return ApiResult.failed();
    }

}
